home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 32 / Mac Magazin and MacEasy Magazine CD - Issue 32.iso / Multimedia / PlayerPRO 4.5.5 Dev.Kit / Plug-Ins / Instruments Import⁄Export Plugs / MINS.c < prev    next >
C/C++ Source or Header  |  1996-06-29  |  5KB  |  219 lines

  1. /*    MINS            */
  2. /*  IMPORT/EXPORT    */
  3. /*    v 1.0            */
  4. /*    1996 by ANR        */
  5.  
  6. #include "PPPlug.h"
  7. #include "sound.h"
  8.  
  9. #if defined(powerc) || defined(__powerc)
  10. enum {
  11.         PlayerPROPlug = kCStackBased
  12.         | RESULT_SIZE(SIZE_CODE( sizeof(OSErr)))
  13.         | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof( OSType)))
  14.         | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof( InstrData*)))
  15.         | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof( sData**)))
  16.         | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof( short*)))
  17.         | STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof( FSSpec*)))
  18.         | STACK_ROUTINE_PARAMETER(6, SIZE_CODE(sizeof( PPInfoPlug*)))
  19. };
  20.  
  21. ProcInfoType __procinfo = PlayerPROPlug;
  22. #else
  23. #include <A4Stuff.h>
  24. #endif
  25.  
  26. OSErr TestMINS( InstrData *CC)
  27. {
  28.     if( CC->type == 0 && CC->numSamples >= 0 && CC->numSamples < MAXSAMPLE) return noErr;
  29.     else return MADFileNotSupportedByThisPlug;
  30. }
  31.  
  32. OSErr MAD2KillInstrument( InstrData *curIns, sData **sample)
  33. {
  34. short            i;
  35. Boolean            IsReading;
  36.  
  37.     for( i = 0; i < curIns->numSamples; i++)
  38.     {
  39.         if( sample[ i] != 0L)
  40.         {
  41.             if( sample[ i]->data != 0L)
  42.             {
  43.                 DisposPtr( (Ptr) sample[ i]->data);
  44.                 sample[ i]->data = 0L;
  45.             }
  46.             DisposPtr( (Ptr) sample[ i]);
  47.             sample[ i] = 0L;
  48.         }
  49.     }
  50.     
  51.     
  52.     for( i = 0; i < 32; i++) curIns->name[ i]    = 0;
  53.     curIns->type        = 0;
  54.     curIns->numSamples    = 0;
  55.     
  56.     /**/
  57.     
  58.     for( i = 0; i < 96; i++) curIns->what[ i]        = 0;
  59.     for( i = 0; i < 12; i++)
  60.     {
  61.         curIns->volEnv[ i].pos        = 0;
  62.         curIns->volEnv[ i].val        = 0;
  63.     }
  64.     for( i = 0; i < 12; i++)
  65.     {
  66.         curIns->pannEnv[ i].pos    = 0;
  67.         curIns->pannEnv[ i].val    = 0;
  68.     }
  69.     curIns->volSize        = 0;
  70.     curIns->pannSize    = 0;
  71.     
  72.     curIns->volSus        = 0;
  73.     curIns->volBeg        = 0;
  74.     curIns->volEnd        = 0;
  75.     
  76.     curIns->pannSus        = 0;
  77.     curIns->pannBeg        = 0;
  78.     curIns->pannEnd        = 0;
  79.  
  80.     curIns->volType        = 0;
  81.     curIns->pannType    = 0;
  82.     
  83.     curIns->volFade        = 0;
  84.     curIns->vibDepth    = 0;
  85.     curIns->vibRate        = 0;
  86.     
  87.     return noErr;
  88. }
  89.  
  90. OSErr main(        OSType                    order,                        // Order to execute
  91.                 InstrData                *InsHeader,                    // Ptr on instrument header
  92.                 sData                    **sample,                    // Ptr on samples data
  93.                 short                    *sampleID,                    // If you need to replace/add only a sample, not replace the entire instrument (by example for 'AIFF' sound)
  94.                                                                     // If sampleID == -1 : add sample else replace selected sample.
  95.                 FSSpec                    *AlienFileFSSpec,            // IN/OUT file
  96.                 PPInfoPlug                *thePPInfoPlug)
  97. {
  98.     OSErr    myErr;
  99.     short    iFileRefI, x;
  100.     long    inOutCount;
  101.     
  102.     #ifndef powerc
  103.         long    oldA4 = SetCurrentA4();             //this call is necessary for strings in 68k code resources
  104.     #endif
  105.     
  106.     switch( order)
  107.     {
  108.         case 'IMPL':
  109.         {
  110.             Ptr                theSound;
  111.             
  112.             myErr = FSpOpenDF( AlienFileFSSpec, fsCurPerm, &iFileRefI);
  113.             if( myErr == noErr)
  114.             {
  115.                 GetEOF( iFileRefI, &inOutCount);
  116.                 
  117.                 theSound = NewPtr( inOutCount);
  118.                 if( theSound == 0L) myErr = MADNeedMemory;
  119.                 else
  120.                 {
  121.                     DisposPtr( theSound);
  122.                     
  123.                     MAD2KillInstrument( InsHeader, sample);
  124.                     
  125.                     // READ instrument header
  126.                     
  127.                     inOutCount = sizeof( InstrData);
  128.                     
  129.                     myErr = FSRead( iFileRefI, &inOutCount, InsHeader);
  130.                     
  131.                     // READ samples headers & data
  132.                     
  133.                     for( x = 0; x < InsHeader->numSamples; x++)
  134.                     {
  135.                         sData *curData = sample[ x] = MADCreateSample();
  136.                         
  137.                         inOutCount = sizeof( sData);
  138.                         
  139.                         myErr = FSRead( iFileRefI, &inOutCount, curData);
  140.                         
  141.                         curData->data = NewPtr( curData->size);
  142.                         if( curData->data != 0L)
  143.                         {
  144.                             inOutCount = curData->size;
  145.                             myErr = FSRead( iFileRefI, &inOutCount, curData->data);
  146.                         }
  147.                     }
  148.                 }
  149.                 
  150.                 FSClose( iFileRefI);
  151.             }
  152.         }
  153.         break;
  154.         
  155.         case 'TEST':
  156.         {
  157.             Ptr    theSound;
  158.             
  159.             myErr = FSpOpenDF( AlienFileFSSpec, fsCurPerm, &iFileRefI);
  160.             if( myErr == noErr)
  161.             {
  162.                 inOutCount = 50L;
  163.                 theSound = NewPtr( inOutCount);
  164.                 if( theSound == 0L) myErr = MADNeedMemory;
  165.                 else
  166.                 {
  167.                     FSRead( iFileRefI, &inOutCount, theSound);
  168.                     
  169.                     myErr = TestMINS( (InstrData*) theSound);
  170.                 }
  171.                 
  172.                 DisposPtr( theSound);
  173.                 
  174.                 FSClose( iFileRefI);
  175.             }
  176.         }
  177.         break;
  178.         
  179.         case 'EXPL':
  180.             
  181.             myErr = FSpCreate( AlienFileFSSpec, 'SNPL', 'MINS', smCurrentScript);
  182.             myErr = FSpOpenDF( AlienFileFSSpec, fsCurPerm, &iFileRefI);
  183.             
  184.             if( myErr == noErr)
  185.             {
  186.                 // Write instrument header
  187.                 
  188.                 inOutCount = sizeof( InstrData);
  189.                 myErr = FSWrite( iFileRefI, &inOutCount, InsHeader);
  190.                 
  191.                 // Write samples headers & data
  192.                 
  193.                 for( x = 0; x < InsHeader->numSamples; x++)
  194.                 {
  195.                     sData    *curData;
  196.                     
  197.                     curData = sample[ x];
  198.                     
  199.                     inOutCount = sizeof( sData);
  200.                     myErr = FSWrite( iFileRefI, &inOutCount, curData);
  201.                     
  202.                     inOutCount = curData->size;
  203.                     myErr = FSWrite( iFileRefI, &inOutCount, curData->data);
  204.                 }
  205.                 FSClose( iFileRefI);
  206.             }
  207.         break;
  208.         
  209.         default:
  210.             myErr = MADOrderNotImplemented;
  211.         break;
  212.     }
  213.     
  214.     #ifndef powerc
  215.         SetA4( oldA4);
  216.     #endif
  217.     
  218.     return myErr;
  219. }